package com.iot.north.app.demo.recieve.service;

import com.fasterxml.jackson.databind.JsonNode;
import com.iot.north.app.demo.utils.DataTransUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/** 按照事件对收到的信息进行处理 */
@Slf4j
@Service
public class EventService {

  /** 处理设备登录 */
  public void devLogin(JsonNode node) {
    log.info("device: " + node.get("iot_sys_devId").asText() + " login");
  }

  /** 处理设备登出 */
  public void devLogout(JsonNode node) {
    log.info("device: " + node.get("iot_sys_devId").asText() + " logout");
  }

  /** 处理云端下发 */
  public void cloudSend(JsonNode node) {
    log.info(
        "cloud send to device: "
            + node.get("iot_sys_devId").asText()
            + DataTransUtil.getJsonFromRawString(node.get("iot_sys_req").asText()).get("data"));
  }

  /** 处理设备上报 */
  public void devSend(JsonNode node) {
    log.info(
        "device: " + node.get("iot_sys_devId").asText() + " send: " + node.get("iot_sys_params"));
  }

  /** 处理设备数据变化 */
  public void dataChanged(JsonNode node) {
    log.info(
        "device: "
            + node.get("iot_sys_devId").asText()
            + " data change to :"
            + DataTransUtil.getJsonFromRawString(node.get("iot_sys_req").asText()).get("data"));
  }
}
